package com.kangaroo.myhome.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.kangaroo.myhome.mapper.TSysFileMapper;
import com.kangaroo.myhome.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kangaroo.myhome.mapper.TSysMenuMapper;
import com.kangaroo.myhome.utils.SecurityUtils;
import com.kangaroo.myhome.vo.ResponseModel;

import tk.mybatis.mapper.util.StringUtil;

@Service
public class FileService {

    @Autowired
    private TSysFileMapper tSysFileMapper;

    /**
     * 
     * @param name
     * @param projectId
     * @return
     */
    public ResponseModel findAll(String name, String projectId,int page,int rows) {
        ResponseModel model = new ResponseModel();

        CommonSearch search = new CommonSearch();
        search.setString1(name);
        search.setString2(projectId);
        search.setPagination(page,rows);
        List<TSysFile> files = tSysFileMapper.selectByPagination(search);
        long count = tSysFileMapper.selectByPaginationCount(search);
        model.setCode(200);
        model.setMessage("数据获取成功");
        model.setDataDataGrid(files,count);
        return model;
    }

    public int saveFileToBD(TSysFile tSysFile){
        int insertSuccessNum = tSysFileMapper.insert(tSysFile);
        return insertSuccessNum;
    }


    public ResponseModel delete(String id) {
        ResponseModel model = new ResponseModel();
        int deleteSuccessNum = tSysFileMapper.deleteByPrimaryKey(id);
        if(deleteSuccessNum>0){
            model.setCode(200);
            model.setMessage("附件删除成功");
        }else{
            model.setCode(201);
            model.setMessage("附件删除失败");
        }
        return model;
    }

}
